//
//  Me.m
//  OrgOnline
//
//  Created by kiko on 16/3/1.
//  Copyright © 2016年 kiko. All rights reserved.
//
#import "Me.h"
#import "Coupon.h"
#import "Evaluate.h"
#import "Order.h"
#import "Finance.h"

@interface Me ()

@end

@implementation Me

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBarHidden = YES;
    self.automaticallyAdjustsScrollViewInsets = NO;
    // Do any additional setup after loading the view.
    NSBundle *bundle = [NSBundle mainBundle];
    NSString *plistPath = [bundle pathForResource:@"mehome"
                                           ofType:@"plist"];
    _listTeams = [[NSArray alloc] initWithContentsOfFile:plistPath];
    //[self configHeadView];
    [self configMidTable];
    
    
}



-(void)configMidTable{
    self.tableview=[[UITableView alloc] initWithFrame:CGRectMake(0, 0, swidth, sheight-44)];
    self.tableview.delegate=self;
    self.tableview.dataSource=self;
    self.tableview.separatorStyle = NO;
     self.tableview.scrollEnabled =YES;
    [self.view addSubview:self.tableview];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBarHidden = NO;
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 8;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if(section==0||section==1||section==2){
        return 1;
    }else if(section==3){
        return 3;}
    else if (section==4||section==5){
        return 2;
    }else
        return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    switch (indexPath.section) {
        case 0:
            return 178;
            break;
        case 1:
            return 81;
            break;
        case 2:
            return 111;
            break;
        default:
            return 40.5;
            break;
    }
    return 40;
}


- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if(section==4||section==5||section==6||section==7){
        return 15;}
    else
        return 0;

}
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section
{
    // Background color
    view.tintColor = [UIColor colorWithRed:241.0f/255.0f green:242.0f/255.0f blue:247.0f/255.0f alpha:1];
    UIView *lview1=[[UIView alloc] initWithFrame:CGRectMake(0, 0 ,swidth, 0.5)];
    lview1.backgroundColor=[UIColor colorWithRed:221.0f/255.0f green:221.0f/255.0f blue:221.0f/255.0f alpha:1];
    UIView *lview2=[[UIView alloc] initWithFrame:CGRectMake(0, 14.5 ,swidth, 0.5)];
    lview2.backgroundColor=[UIColor colorWithRed:221.0f/255.0f green:221.0f/255.0f blue:221.0f/255.0f alpha:1];
    [view addSubview:lview1];
    [view addSubview:lview2];
}


- (void)go:(UIButton *)button {
    if(button.tag==1){
         Coupon * view = [[Coupon alloc]init];
        [view setHidesBottomBarWhenPushed:YES];
        [self.navigationController pushViewController:view animated:YES];
    }else if(button.tag==2){
        Evaluate * view = [[Evaluate alloc]init];
        [view setHidesBottomBarWhenPushed:YES];
        [self.navigationController pushViewController:view animated:YES];
    }else if (button.tag==3){
        Finance * view = [[Finance alloc]init];
        [view setHidesBottomBarWhenPushed:YES];
        [self.navigationController pushViewController:view animated:YES];
    }else if (button.tag==4){
        Order *view = [[Order alloc]init];
        [view setHidesBottomBarWhenPushed:YES];
        [self.navigationController pushViewController:view animated:YES];
    }
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"CellIdentifier";
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    NSArray *list1=[_listTeams objectAtIndex:0];
    NSArray *list2=[_listTeams objectAtIndex:1];
    if (indexPath.section==0) {
        UIImageView *img1=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0 ,swidth, 178)];
        img1.image=[UIImage imageNamed:@"mebg"];
        UIImageView *img2=[[UIImageView alloc] initWithFrame:CGRectMake(157.5, 35.5 ,90, 90)];
        img2.image=[UIImage imageNamed:@"melogoframe"];
        UIImageView *img3=[[UIImageView alloc] initWithFrame:CGRectMake(170, 60 ,70,35)];
        img3.image=[UIImage imageNamed:@"melogo"];
        UILabel *label1=[[UILabel alloc] initWithFrame:CGRectMake(0, 135.5 ,swidth, 20)];
        label1.text=@"艾迪儿教育";
        label1.textAlignment= NSTextAlignmentCenter;
        
        UIButton *but=[[UIButton alloc] initWithFrame:CGRectMake(swidth-31, 99,10, 20)];
        UIImageView *img=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0 ,10,20)];
        img.image=[UIImage imageNamed:@"mebgarrow"];
        [but addSubview:img];
        
        //[cell.contentView addSubview:but];
        [cell.contentView addSubview:img1];
        [cell.contentView addSubview:img2];
        [cell.contentView addSubview:img3];
        [cell.contentView addSubview:label1];
        [cell.contentView addSubview:but];
        
    }else if(indexPath.section==1){
        NSDictionary *rowDict1 = [list1 objectAtIndex:0];
        NSDictionary *rowDict2 = [list1 objectAtIndex:1];
        NSDictionary *rowDict3 = [list1 objectAtIndex:2];
        UIButton *but1=[[UIButton alloc] initWithFrame:CGRectMake(29.5, 10,60, 55)];
        UIButton *but2=[[UIButton alloc] initWithFrame:CGRectMake(175.5, 10,60, 50)];
        UIButton *but3=[[UIButton alloc] initWithFrame:CGRectMake(321, 10,60, 50)];
        
        
        UILabel *t1=[[UILabel alloc] initWithFrame:CGRectMake(0, 30 ,80, 18)];
        t1.text=[rowDict1 objectForKey:@"name"];
        t1.font=[UIFont systemFontOfSize:13];
        t1.textColor=[UIColor colorWithRed:51.0f/255.0f green:51.0f/255.0f blue:51.0f/255.0f alpha:1];
        UIImageView *img1=[[UIImageView alloc] initWithFrame:CGRectMake(8, 0 ,27,25)];
        img1.image=[UIImage imageNamed:[rowDict1 objectForKey:@"img"]];
        [but1 addSubview:t1];
        [but1 addSubview:img1];
        but1.tag=1;
        [but1 addTarget:self action:@selector(go:) forControlEvents:UIControlEventTouchUpInside];

        UILabel *t2=[[UILabel alloc] initWithFrame:CGRectMake(0, 30 ,80, 18)];
        t2.text=[rowDict2 objectForKey:@"name"];
        t2.font=[UIFont systemFontOfSize:13];
        t2.textColor=[UIColor colorWithRed:51.0f/255.0f green:51.0f/255.0f blue:51.0f/255.0f alpha:1];
        UIImageView *img2=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0 ,27,25)];
        img2.image=[UIImage imageNamed:[rowDict2 objectForKey:@"img"]];
        but2.tag=2;
        [but2 addTarget:self action:@selector(go:) forControlEvents:UIControlEventTouchUpInside];
        [but2 addSubview:t2];
        [but2 addSubview:img2];
        
        
        //[button addTarget:self action:@selector(forwardButtonUpInsideAction) forControlEvents:UIControlEventTouchUpInside];
        UILabel *t3=[[UILabel alloc] initWithFrame:CGRectMake(0, 30 ,80, 18)];
        t3.text=[rowDict3 objectForKey:@"name"];
        t3.font=[UIFont systemFontOfSize:13];
        t3.textColor=[UIColor colorWithRed:51.0f/255.0f green:51.0f/255.0f blue:51.0f/255.0f alpha:1];
        UIImageView *img3=[[UIImageView alloc] initWithFrame:CGRectMake(0, 0 ,27,25)];
        img3.image=[UIImage imageNamed:[rowDict3 objectForKey:@"img"]];
        but3.tag=3;
        [but3 addTarget:self action:@selector(go:) forControlEvents:UIControlEventTouchUpInside];
        [but3 addSubview:t3];
        [but3 addSubview:img3];
        
        
        
        UIView *lview=[[UIView alloc] initWithFrame:CGRectMake(0, 66 ,swidth, 15)];
        lview.backgroundColor=[UIColor colorWithRed:241.0f/255.0f green:242.0f/255.0f blue:247.0f/255.0f alpha:1];
        UIView *lview1=[[UIView alloc] initWithFrame:CGRectMake(0, 66 ,swidth, 0.5)];
        lview1.backgroundColor=[UIColor colorWithRed:221.0f/255.0f green:221.0f/255.0f blue:221.0f/255.0f alpha:1];
        UIView *lview2=[[UIView alloc] initWithFrame:CGRectMake(0, 80.5 ,swidth, 0.5)];
        lview2.backgroundColor=[UIColor colorWithRed:221.0f/255.0f green:221.0f/255.0f blue:221.0f/255.0f alpha:1];
        [cell.contentView addSubview:but1];
        [cell.contentView addSubview:but2];
        [cell.contentView addSubview:but3];
        [cell.contentView addSubview:lview];
        [cell.contentView addSubview:lview1];
        [cell.contentView addSubview:lview2];
    }
    else if (indexPath.section==2){
        UILabel *label2=[[UILabel alloc] initWithFrame:CGRectMake(10, 10 ,100, 20)];
        label2.text=@"订单";
        label2.font=[UIFont systemFontOfSize:14];
        label2.textColor=[UIColor colorWithRed:51.0f/255.0f green:51.0f/255.0f blue:51.0f/255.0f alpha:1];
        
        UIButton *but=[[UIButton alloc] initWithFrame:CGRectMake(swidth-90, 10,120, 20)];
        UILabel *t=[[UILabel alloc] initWithFrame:CGRectMake(0, 0 ,60, 20)];
        t.text=@"全部订单";
        t.font=[UIFont systemFontOfSize:11];
        t.textColor=[UIColor colorWithRed:153.0f/255.0f green:153.0f/255.0f blue:153.0f/255.0f alpha:1];
        UIImageView *img=[[UIImageView alloc] initWithFrame:CGRectMake(52, 5 ,5,10)];
        img.image=[UIImage imageNamed:@"mearrow"];
        but.tag=4;
        [but addTarget:self action:@selector(go:) forControlEvents:UIControlEventTouchUpInside];
        [but addSubview:t];
        [but addSubview:img];
        
    
        UIView *line=[[UIView alloc] initWithFrame:CGRectMake(10, 29,swidth-10, 0.5)];
        line.backgroundColor=[UIColor colorWithRed:221.0f/255.0f green:221.0f/255.0f blue:221.0f/255.0f alpha:1];
        
        
        NSDictionary *rowDict1 = [list2 objectAtIndex:0];
        NSDictionary *rowDict2 = [list2 objectAtIndex:1];
        NSDictionary *rowDict3 = [list2 objectAtIndex:2];
        
        UIButton *but1=[[UIButton alloc] initWithFrame:CGRectMake(29.5, 39,60, 55)];
        UIButton *but2=[[UIButton alloc] initWithFrame:CGRectMake(175.5, 39,60, 50)];
        UIButton *but3=[[UIButton alloc] initWithFrame:CGRectMake(321, 39,60, 50)];
        
        
        UILabel *t1=[[UILabel alloc] initWithFrame:CGRectMake(0, 30 ,80, 18)];
        t1.text=[rowDict1 objectForKey:@"name"];
        t1.font=[UIFont systemFontOfSize:13];
        t1.textColor=[UIColor colorWithRed:102.0f/255.0f green:102.0f/255.0f blue:102.0f/255.0f alpha:1];
        UIImageView *img1=[[UIImageView alloc] initWithFrame:CGRectMake(8, 3 ,27,18)];
        img1.image=[UIImage imageNamed:[rowDict1 objectForKey:@"img"]];
        [but1 addSubview:t1];
        [but1 addSubview:img1];
        
        
        UILabel *t2=[[UILabel alloc] initWithFrame:CGRectMake(0, 30 ,80, 18)];
        t2.text=[rowDict2 objectForKey:@"name"];
        t2.font=[UIFont systemFontOfSize:13];
        t2.textColor=[UIColor colorWithRed:102.0f/255.0f green:102.0f/255.0f blue:102.0f/255.0f alpha:1];
        UIImageView *img2=[[UIImageView alloc] initWithFrame:CGRectMake(4, 3 ,27,18)];
        img2.image=[UIImage imageNamed:[rowDict2 objectForKey:@"img"]];
        [but2 addSubview:t2];
        [but2 addSubview:img2];
        
        
        //[button addTarget:self action:@selector(forwardButtonUpInsideAction) forControlEvents:UIControlEventTouchUpInside];
        UILabel *t3=[[UILabel alloc] initWithFrame:CGRectMake(0, 30 ,80, 18)];
        t3.text=[rowDict3 objectForKey:@"name"];
        t3.font=[UIFont systemFontOfSize:13];
        t3.textColor=[UIColor colorWithRed:102.0f/255.0f green:102.0f/255.0f blue:102.0f/255.0f alpha:1];
        UIImageView *img3=[[UIImageView alloc] initWithFrame:CGRectMake(4, 3 ,27,18)];
        img3.image=[UIImage imageNamed:[rowDict3 objectForKey:@"img"]];
        [but3 addSubview:t3];
        [but3 addSubview:img3];
        
        UIView *lview=[[UIView alloc] initWithFrame:CGRectMake(0, 66 ,swidth, 15)];
        lview.backgroundColor=[UIColor colorWithRed:241.0f/255.0f green:242.0f/255.0f blue:247.0f/255.0f alpha:1];
        
        
        
        [cell.contentView addSubview:but1];
        [cell.contentView addSubview:but2];
        [cell.contentView addSubview:but3];
        [cell.contentView addSubview:but];
        [cell.contentView addSubview:line];
        [cell.contentView addSubview:label2];
        
        UIView *lview1=[[UIView alloc] initWithFrame:CGRectMake(0, 96 ,swidth, 15)];
        lview1.backgroundColor=[UIColor colorWithRed:241.0f/255.0f green:242.0f/255.0f blue:247.0f/255.0f alpha:1];
        UIView *lview2=[[UIView alloc] initWithFrame:CGRectMake(0, 96.5 ,swidth, 0.5)];
        lview2.backgroundColor=[UIColor colorWithRed:221.0f/255.0f green:221.0f/255.0f blue:221.0f/255.0f alpha:1];
        UIView *lview3=[[UIView alloc] initWithFrame:CGRectMake(0, 111 ,swidth, 0.5)];
        lview3.backgroundColor=[UIColor colorWithRed:221.0f/255.0f green:221.0f/255.0f blue:221.0f/255.0f alpha:1];

        
        
        [cell.contentView addSubview:lview1];
        [cell.contentView addSubview:lview2];
        [cell.contentView addSubview:lview3];
       
    }else{
    
        NSUInteger row = [indexPath row];
        NSUInteger section=[indexPath section];
        NSArray *lists=[_listTeams objectAtIndex:section-1];
        NSDictionary *rowDict = [lists objectAtIndex:row];
        
        
        UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(10, 8.5, 24, 24)];
        //imageView.backgroundColor = [UIColor redColor];
        imageView.contentMode = UIViewContentModeScaleAspectFit;
        imageView.image=[UIImage imageNamed:[rowDict objectForKey:@"img"]];
        [cell.contentView addSubview:imageView];
        

        UILabel *nameLabel=[[UILabel alloc]initWithFrame:CGRectMake(45, 5, 100, 35)];
        nameLabel.text=  [rowDict objectForKey:@"name"];
        nameLabel.textColor=[UIColor colorWithRed:51.0f/255.0f green:51.0f/255.0f blue:51.0f/255.0f alpha:1];
        nameLabel.font = [UIFont systemFontOfSize:13];
        [cell.contentView addSubview:nameLabel];

        UIImageView *indicatorview = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"mearrow"]];
        [indicatorview setFrame:CGRectMake(0, 0, 5, 10)];
        cell.accessoryView = indicatorview;
        
        
        UIView *line = [[UIView alloc] initWithFrame:CGRectMake(10, 40.5, swidth, 0.5)];
        line.backgroundColor = [UIColor colorWithRed:221.0f/255.0f green:221.0f/255.0f blue:221.0f/255.0f alpha:1];
        [cell.contentView addSubview:line];

        

    }
    

    return cell;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
